package com.tarena.lbs.business.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.business.pojo.param.BusinessParam;
import com.tarena.lbs.business.pojo.query.BusinessQuery;
import com.tarena.lbs.business.pojo.vo.BusinessStoreVO;
import com.tarena.lbs.business.pojo.vo.BusinessVO;
import com.tarena.lbs.business.servcie.BusinessService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "商家相关功能接口")
@Slf4j
@RestController
public class BusinessController {
	
	@Autowired
	private BusinessService businessService;
	
	/**
	 * 新增商家
	 *
	 * @param param 新增商家参数
	 * @return 新增结果
	 */
	@Operation(summary = "新增商家")
	@PostMapping("/admin/basic/business/info/save")
	public Result save(@Validated @RequestBody BusinessParam param) throws BusinessException {
		log.debug(">>>新增商家-服务-入参，BusinessParam：{}", param);
		businessService.save(param);
		return Result.success();
	}
	
	
	/**
	 * 分页查询商家列表
	 *
	 * @param query 查询参数
	 * @return 商家列表
	 */
	@Operation(summary = "查询商家列表")
	@GetMapping("/admin/basic/business/info/list")
	public Result<PageResult<BusinessVO>> pageList(BusinessQuery query) throws BusinessException {
		log.debug(">>>查询商家列表-服务-入参：{}", query);
		PageResult<BusinessVO> pageResult = null;
		pageResult = businessService.pageList(query);
		return new Result<>(pageResult);
	}
	
	
	/**
	 * 查询商家详情
	 *
	 * @param businessId 商家ID
	 * @return 商家详情
	 * @throws BusinessException 业务异常
	 */
	@Operation(summary = "商家详情")
	@GetMapping("/basic/business/info/detail/{id}")
	public Result<BusinessStoreVO> busiStoreDetail(@PathVariable("id") Integer businessId) throws BusinessException {
		log.debug(">>>查询商家详情-服务-入参：{}", businessId);
		BusinessStoreVO vo = businessService.getDetail(businessId);
		return new Result<>(vo);
	}
	
}
